﻿using AnesSystem.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace AnesSystem.Converters
{
  public  class EventTypeCode2NameConvert : IValueConverter
    {
       

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                if (value == null) return "";
                ConfigEventTypesModel configEventTypesModel =
                    DataManager.Instance.ConfigEventTypesModelList.ToList().Find(
                        O => O.Code.Equals(value.ToString()));
                if(configEventTypesModel == null) return "";
                return configEventTypesModel.Name;
            }
            catch (Exception ex)
            {
                Common.LogHelper.Error(this.GetType(), ex);
                return value;

            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString()))
            {
                return "eventType_2";
            }
            else
            {
                ConfigEventTypesModel configEventTypesModel =
                   DataManager.Instance.ConfigEventTypesModelList.ToList().Find(
                       O => O.Name.Equals(value.ToString()));
                if (configEventTypesModel == null)
                {
                    return "eventType_2";
                }
                else
                {
                    return configEventTypesModel.Code;
                }
            }
          
        }

     
    }
}
